//
//  RootViewController.m
//  TMSDriver
//
//  Created by admin on 2018/3/7.
//  Copyright © 2018年 zhuchongjin All rights reserved.
//

#import "RootViewController.h"
#import "HomeVC.h"
#import "MineViewController.h"
#import "SourceViewController.h"

@interface RootViewController ()<UITabBarDelegate,UITabBarControllerDelegate>
@property (strong, nonatomic) NSMutableArray * controllerArray;
@property (nonatomic, strong) UITabBarItem *lastItem;
@property (nonatomic,strong) UINavigationController * nav3;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTab];
    // Do any additional setup after loading the view.
}
-(void)createTab{
    
    NSDictionary * dict1 = @{NSFontAttributeName:[UIFont systemFontOfSize:12]};
    NSDictionary * dict = @{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor cjMainColor]};
    
    // 我的
    MineViewController * first = [[MineViewController alloc]init];
    first.tabBarItem = [[UITabBarItem alloc]initWithTitle:CJLString(@"我的") image:[[UIImage imageNamed:@"zcj_tab_mine_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"zcj_tab_mine_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [first.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    [first.tabBarItem setTitleTextAttributes:dict1 forState:UIControlStateNormal];
    UINavigationController * nav1 = [[UINavigationController alloc]initWithRootViewController:first];
    
    // 首页
    HomeVC* message = [[HomeVC alloc]init];
    message.tabBarItem = [[UITabBarItem alloc]initWithTitle:CJLString(@"首页") image:[[UIImage imageNamed:@"zcj_tab_home_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"zcj_tab_home_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [message.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    [message.tabBarItem setTitleTextAttributes:dict1 forState:UIControlStateNormal];
    UINavigationController * nav2 = [[UINavigationController alloc]initWithRootViewController:message];
    
    // 我的货源
    SourceViewController * publish = [[SourceViewController alloc]init];
    publish.tabBarItem = [[UITabBarItem alloc]initWithTitle:CJLString(@"运单") image:[[UIImage imageNamed:@"zcj_tab_yundan_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"zcj_tab_yundan_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [publish.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    [publish.tabBarItem setTitleTextAttributes:dict1 forState:UIControlStateNormal];
    self.nav3 = [[UINavigationController alloc]initWithRootViewController:publish];

    
    [[UITabBar appearance]setTranslucent:NO];
//    if (@available(iOS 13.0, *)) {
        [[UITabBar appearance] setUnselectedItemTintColor:CJRGB16Color(0x999999)];
//    }
    [[UITabBar appearance] setBackgroundColor:[UIColor cjWhiteColor]];
    self.viewControllers = @[nav2,self.nav3,nav1];
    self.delegate = self;
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0){
    
    if (self.nav3 == viewController) {
        CJSendNotify(@"clickTabBarReloadData", nil);
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
